#include "threedimensioncrosssectionmodule.h"

// #include "threedimensioncrosssectionform.h"
#include "util.h"

#include "threedimensioncrosssectionfind.h"
#include "threedimensioncrosssectionstandardedit1.h"

#include <QDebug>
#include <QAction>


struct ThreeDimensionCrossSectionModulePrivate
{
    ThreeDimensionCrossSectionModulePrivate() {
        for (const auto& str : {"Net Boundary", "Extended Boundary"}) {
            auto action = new QAction(str);
            action->setCheckable(true);
            action->setChecked(true);//初始化选中
            actions.append(action);
        }


        wgts.append(new ThreeDimensionCrossSectionStandardEdit1);

        wgt = new ThreeDimensionCrossSectionFind();
    }
    ~ThreeDimensionCrossSectionModulePrivate(){
        //delete centerWidge;
        qDeleteAll(actions);
    }
    //ThreeDimensionCrossSectionForm* centerWidge = nullptr;
    QList<QAction*> actions;
    QString dbTableName = csUtil::tableName;
    ThreeDimensionCrossSectionFind* wgt = nullptr;
    QList<IModuleEditFrameInterface *> wgts;
};

ThreeDimensionCrossSectionModule::ThreeDimensionCrossSectionModule(QObject* parent)
    : QObject(parent)
{
    m_data = new ThreeDimensionCrossSectionModulePrivate();
}

ThreeDimensionCrossSectionModule::~ThreeDimensionCrossSectionModule()
{
    delete m_data;
}

QString ThreeDimensionCrossSectionModule::name() const
{
    return "ThreeDimensionCrossSection";
}

void ThreeDimensionCrossSectionModule::initialize()
{
    qDebug() << "ThreeDimensionCrossSection模块已初始化";
    // 在这里实现模块的初始化逻辑

}

QString ThreeDimensionCrossSectionModule::treeName() const
{
    return "ThreeDimensionCrossSection";
}

QString ThreeDimensionCrossSectionModule::treeParentName() const
{
    return "Design";
}

QIcon ThreeDimensionCrossSectionModule::treeIcon() const
{
    return QIcon(":/threedimensioncrosssection/icons/threedimensioncrosssection-default.png");
}

QIcon ThreeDimensionCrossSectionModule::treeSelectedIcon() const
{
    return QIcon(":/threedimensioncrosssection/icons/threedimensioncrosssection-select.png");
}

std::tuple<QString, QString, QString> ThreeDimensionCrossSectionModule::toolFilePath() const
{
    return {"frame_treeItemTools", "verticalLayout_treeItemTool", "ui\\threedimensioncrosssectiontool.ui"};
}

IModuleForm *ThreeDimensionCrossSectionModule::centerWidget()
{
    // if (m_data->centerWidge == nullptr)
    //     m_data->centerWidge = new ThreeDimensionCrossSectionForm();
    // return m_data->centerWidge;
    return nullptr;
}

QList<QAction *> ThreeDimensionCrossSectionModule::highLightActions()
{
    return m_data->actions;
}

QString ThreeDimensionCrossSectionModule::dbTableName()
{
    return m_data->dbTableName;
}

QList<IModuleEditFrameInterface *> ThreeDimensionCrossSectionModule::editWidgets()
{
    return m_data->wgts;
}

QList<TableInfoData> ThreeDimensionCrossSectionModule::tableInfoModels()
{
    QList<TableInfoData> ret;

    TableInfoData lm;
    lm.headers << "Status"
               << "Name"
               << "Laminate"
               << "Cross Section Curve"
               << "Ply/Layer Scale";

    lm.title = "Standard";
    lm.table2dbKey = {{"Status", "Status"},
                      {"Name", "Name"},
                      {"Laminate", "Laminate"},
                      {"Cross Section Curve", "CrossSectionCurve"},
                      {"Ply/Layer Scale", "PlyLayerScale"}};

    lm.colSetting = {
        {160, 120, QHeaderView::Interactive},  // 第一列
        {90, 80, QHeaderView::Interactive},  // 第二列（固定宽度）
        {90, 80, QHeaderView::Interactive}, // 第三列
        {160, 120, QHeaderView::Interactive},  // 第四列
        {25, 25, QHeaderView::Stretch}       // 第九列（拉伸填充）
    };
    ret.append(lm);

    return ret;
}

IFindWidget *ThreeDimensionCrossSectionModule::findWidget()
{

    return m_data->wgt;

}

void ThreeDimensionCrossSectionModule::processHighlightData(const QVariantMap &data, bool isHighlight)
{
    /*auto LayupSurface = data.value("LayupSurface").toString();
    auto Origin = data.value("Origin").toString();
    isHighlight ?
    CADInterface::instance().fibCreateNormalLineAndArrowhead(LayupSurface, Origin) :
    CADInterface::instance().fibDeleteNormalLineAndArrowhead(Origin);*/
}

QMap<QString, QString> ThreeDimensionCrossSectionModule::highlightTypes()
{
    return {{"Net Boundary", "NetBoundary"},
            {"Extended Boundary", "ExtBoundary"},};
}
